package com.hjm.project.area.service.impl;


import com.google.common.collect.Maps;
import com.hjm.common.constant.DictConstants;
import com.hjm.common.utils.text.Convert;
import com.hjm.framework.cache.RedisCache;
import com.hjm.framework.cache.RedisUtils;
import com.hjm.project.area.domain.Area;
import com.hjm.project.area.mapper.AreaMapper;
import com.hjm.project.area.service.IAreaService;
import com.hjm.project.system.dict.domain.DictType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.List;
import java.util.Map;

/**
 * areaService业务层处理
 *
 * @author LOVE
 * @date 2020-10-18
 */
@Service
public class AreaServiceImpl implements IAreaService {
    @Autowired
    private AreaMapper areaMapper;

    @Autowired
    private RedisCache redisCache;
    @PostConstruct
    public void init() {
        if (!redisCache.hasKey(DictConstants.getAreaKey())) {
            List<Area> areaList = areaMapper.selectAreaList(null);
            if (areaList != null) {
                redisCache.setCacheList(DictConstants.getAreaKey(), areaList);
            }
        }


    }

    /**
     * 查询area
     *
     * @param areaId areaID
     * @return area
     */
    @Override
    public Area selectAreaById(Long areaId) {
        return areaMapper.selectAreaById(areaId);
    }

    /**
     * 查询area列表
     *
     * @param area area
     * @return area
     */
    @Override
    public List<Area> selectAreaList(Area area) {
        return areaMapper.selectAreaList(area);
    }

    /**
     * 新增area
     *
     * @param area area
     * @return 结果
     */
    @Override
    public int insertArea(Area area) {
        return areaMapper.insertArea(area);
    }

    /**
     * 修改area
     *
     * @param area area
     * @return 结果
     */
    @Override
    public int updateArea(Area area) {
        return areaMapper.updateArea(area);
    }

    /**
     * 删除area对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteAreaByIds(String ids) {
        return areaMapper.deleteAreaByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除area信息
     *
     * @param areaId areaID
     * @return 结果
     */
    @Override
    public int deleteAreaById(Long areaId) {
        return areaMapper.deleteAreaById(areaId);
    }


    @Override
    public List<Map<String, Object>> findQBArea(String index, String area_type) throws Exception {
        Map<String, String> map = Maps.newHashMap();
        map.put("index", index);
        map.put("area_type", area_type);
        return areaMapper.findQBArea(map);
    }

    @Override
    public Map<String, Object> findQBAreaCode(Map map) {
        return areaMapper.findQBAreaCode(map);
    }
}
